package com.hrt.common.web;

import com.btcode.exception.MsgException;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.io.Reader;
import oracle.sql.CLOB;

public class SqlClobAdapter extends TypeAdapter<CLOB> {

    @Override
    public void write(JsonWriter out, CLOB value) throws IOException {
        try {
            Reader inStreamDoc = value.getCharacterStream();

            char[] tempDoc = new char[(int) value.length()];
            inStreamDoc.read(tempDoc);
            inStreamDoc.close();
            out.value(new String(tempDoc));
        }
        catch (Exception e) {
            throw new MsgException("转换出错", e);
        }
    }

    @Override
    public CLOB read(JsonReader in) throws IOException {
        // TODO Auto-generated method stub
        return null;
    }

}
